package com.ruoyi.business.service.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.response.TaskUserExportRes;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.TaskUserMapper;
import com.ruoyi.business.domain.TaskUser;
import com.ruoyi.business.service.ITaskUserService;

/**
 * 任务分配用户Service业务层处理
 * 
 * @author Eric
 * @date 2024-03-17
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class TaskUserServiceImpl extends ServiceImpl<TaskUserMapper, TaskUser> implements ITaskUserService {

    @Override
    public Long[] getTaskUserIds(Long taskId) {
        LambdaQueryWrapper<TaskUser> lambdaQueryWrapper = Wrappers.lambdaQuery(TaskUser.class);
        lambdaQueryWrapper.select(TaskUser::getUserId);
        lambdaQueryWrapper.eq(TaskUser::getTaskId, taskId);
        List<Long> userList = baseMapper.selectObjs(lambdaQueryWrapper).stream().map(o -> (Long) o)
                .collect(Collectors.toList());
        return ArrayUtil.toArray(userList, Long.class);
    }

    @Override
    public List<TaskUserExportRes> getExportList(Long taskId) {
        return baseMapper.getExportList(taskId);
    }
}
